<template>
  <div class="view-fill">
    <div class="app-container-flex">
      <NewFullScreen
        v-model="showDialog"
        :title="title"
        @returnBack="returnBack"
      >
        <div class="model-panel">
          <div class="model-panel-title">
            <p>{{ $t('basic_information') }}</p>
          </div>
          <div class="model-panel-body">
            <basic-information :info="formInfo" />
          </div>
        </div>
        <div class="model-panel">
          <div class="model-panel-title">
            <Tooltip text="产品信息" />
          </div>
          <div class="model-panel-body">
            <div class="flex_full_item">
              <!-- 表格 -->
              <page-table
              :refresh="tableInfo.refresh"
              :init-curpage="tableInfo.initCurpage"
              v-model:data="tableInfo.data"
              :api="tableInfo.api"
              :check-box="false"
              :tab-index="true"
              :listen-height="false"
              :pager="false"
              :summary="true"
              :summary-field-list="tableInfo.summaryFieldList"
              v-model:query="filterInfo.query"
              :field-list="tableInfo.fieldList"
              >
              </page-table>
            </div>
          </div>
        </div>
      </NewFullScreen>
    </div>
  </div>
</template>

<script setup name="smartCabinetInventoryDetails">
import {
  getSmartCabinetListById,
  getSmartCabinetProductAll,
} from '@/api/smartCabinet'
import { getSmartCabinetStockCustomizeListAll } from '@/api/smartCabinet.js'
import { getCustomizeSetting } from '@/api/customize'
const { proxy } = getCurrentInstance()
const emits = defineEmits()
const props = defineProps({
  visible: {
    type: Boolean,
    default: false,
  },
  id: {
    type: String,
    default: '',
  },
  smartCabinetId: {
    type: String,
    default: '',
  },
})
const title = ref('智能柜柜存详情')
// 过滤相关配置
const filterInfo = ref({
  query: {
    curPage: 1,
    pageSize: 99999,
    queryMap: {
      smartCabinetId:{
        queryType: 'IN',
        queryCategory: 'AND',
        value: props.smartCabinetId
      }
    },
    customizeUserVO: {},
  },
  list: [],
})
const formInfo = ref({
  data: {},
  fieldList: [
    {
      label: '智能柜编号',
      value: 'code',
    },
    {
      label: '智能柜名称',
      value: 'name',
    },
    {
      label: '智能柜类型',
      value: 'typeValue',
    },
    {
      label: '位置',
      value: 'address',
    },
    {
      label: '所属仓库',
      value: 'depotName',
    },
    {
      label: '所属部门',
      value: 'deptName',
    },
    // {
    //   label: '智能柜状态',
    //   value: 'statusValue',
    // },
    // {
    //   label: '存储条件',
    //   value: 'storageConditionValue',
    // },
    // {
    //   label: '是否支持温湿度监控',
    //   value: 'temperatureHumitureMonitorValue',
    // },
    // {
    //   label: '是否定时消耗',
    //   value: 'autoConsumeValue',
    // },
    // {
    //   label: '消耗时间(每天)',
    //   value: 'consumeTime',
    // },
    // {
    //   label: '出柜消耗间隔',
    //   value: 'consumeIntervalTimeValue',
    // },
    // {
    //   label: '备注',
    //   value: 'remark',
    //   type: 'popover',
    // },
  ],
  labelWidth: '120px',
})
// 表格相关
const tableInfo = ref({
  refresh: 1,
  initCurpage: 1,
  data: [],
  copyData: [],
  api: undefined,
  selections: [],
  fieldList: [],
  summaryFieldList: [
    { value: 'qty', formatter: proxy.$fn.qtyFormatter },
    { value: 'sumAmount', formatter: proxy.$fn.TripartiteMethod },
  ],
  handle: {},
})

const showDialog = computed({
  get() {
    return props.visible
  },
  set(val) {
    // 更新父组件visible
    emits('update:visible', val)
  },
})

onMounted(() => {
  getDeatil()
  let obj = {}
  tableInfo.value.fieldList = Object.values({
    ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
    ...proxy.$fn.deepClone(obj),
  })
  getCustomize()
})
function getList() {
  tableInfo.value.refresh = Math.random()
}
function getCustomize() {
  let param = {
    tableKey:
      'singleSmartCabinetStockDetail-com.slip.spd.entity.vo.smartCabinet.SmartCabinetStockVO',
  }
  getCustomizeSetting(param).then((res) => {
    if (res && res.success) {
      let data = res.data
      filterInfo.value.query.customizeUserVO = res.data
      tableInfo.value.fieldList = proxy.$fn.setFieldList(
        tableInfo.value.fieldList,
        data.detail
      )
      tableInfo.value.api = getSmartCabinetStockCustomizeListAll
      getList()
    }
  })
}
const returnBack = () => {
  emits('returnBack')
}
const getDeatil = () => {
  getSmartCabinetListById(props.smartCabinetId).then((resp) => {
    if (resp && resp.success) {
      formInfo.value.data = resp.data
    }
  })
}
</script>

<style scoped></style>
